/*
 * Copyright (c) 2015. For Intelligent Group.
 */

package com.intelligent.ispc.foundation.pdf;

import com.itextpdf.text.Font;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfPCell;

/**
 * Created by cherry on 2016/8/12.
 */
public final class PdfUtil {

    public static Paragraph createParagraph(String content, Font font) {
        Paragraph paragraph = null;
        if (font == null) {
            paragraph = new Paragraph(content);
        } else {
            paragraph = new Paragraph(content, font);
        }
        return paragraph;
    }

    public static Paragraph createParagraph(String content) {
        return createParagraph(content, null);
    }

    public static PdfPCell createTextCell(String value, ExCellStyle exCellStyle) {
        PdfPCell cell = null;
        if (exCellStyle != null) {
            cell = new PdfPCell(createParagraph(value, exCellStyle.getFont()));
            cell.setBorder(exCellStyle.getBorder());
            cell.setBackgroundColor(exCellStyle.getBgColor());
            cell.setBorderColor(exCellStyle.getBorderColor());
            cell.setHorizontalAlignment(exCellStyle.getAlign());
            cell.setColspan(exCellStyle.getColspan());
        } else {
            cell = new PdfPCell(createParagraph(value));
        }
        return cell;
    }

    public static PdfPCell createTextCell(String value) {
        return createTextCell(value, null);
    }
}
